<template>
  <div class="search">
    <f-form ref="form" :action="api.version" :form-key="this.formItem.versionId" :file-ids="fileIds">
      <f-form-item label="版本名称" name="verName" :required="true" :value="formItem.verName"/>
      <f-form-item label="版本号" name="verNo" :required="true" :value="formItem.verNo"/>
      <f-form-item label="应用类型" name="verCode" type="radio" v-if="loaded" dataType="string" :required="true" :data="verCodeData" :value="formItem.verCode" label-key="label" value-key="value" />
      <f-form-item label="下载链接" type="other" v-if="formItem.verCode=='android'">
        <upload-file :value="formItem.verUrl" accept=".apk" @change="uploadSuccess"></upload-file>
      </f-form-item>
      <f-form-item label="下载链接" name="verUrl" :value="formItem.verUrl" v-if="formItem.verCode=='ios'"/>
      <f-form-item label="更新内容" name="verContent" type="textarea" :value="formItem.verContent"/>
    </f-form>
  </div>
</template>

<script>
  export default {
    name: 'versionForm',
    props: {},
    data() {
      return {
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载轮播图组件
        fileIds: [],//上传文件ID
        formItem: this.getFormItem(),
        verCodeData: [{ label: '安卓', value: 'android' }, { label: '苹果', value: 'ios' }]
      }
    },
    methods: {
      getFormItem() {
        return {
          versionId: '',
          verName: '',
          verNo: '',
          verTitle: '',
          verContent: '',
          verUrl: '',
          verContent:'',
          verCode: 'android',
          forceUpdate: 0
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        this.isAdd = true
        if (data && data.versionId) {
          this.$refs.form.getDetails({ versionId: data.versionId }, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //文件上传回调
      uploadSuccess(fileUrl, file) {
        this.formItem.verUrl = fileUrl
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit(this.formItem,callback)
      },
      verCodeChange(val) {
        this.formItem.verCode = val
      }
    },
    created() {

    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
